using System;
using System.Collections.Generic;
using UnityEngine;

namespace NodeCanvas
{
	public class MonoManager : MonoBehaviour
	{
		private List<Action> updateMethods = new List<Action>();

		private static bool isQuiting;

		private static MonoManager _current;

		public static MonoManager current
		{
			get
			{
				if (_current == null && !isQuiting)
				{
					_current = new GameObject("_MonoManager").AddComponent<MonoManager>();
				}
				return _current;
			}
			private set
			{
				_current = value;
			}
		}

		public static void Create()
		{
			_current = current;
		}

		public void AddMethod(Action method)
		{
			updateMethods.Add(method);
		}

		public void RemoveMethod(Action method)
		{
			updateMethods.Remove(method);
		}

		private void OnApplicationQuit()
		{
			isQuiting = true;
		}

		private void Awake()
		{
			if (_current != null && _current != this)
			{
				UnityEngine.Object.DestroyImmediate(base.gameObject);
				return;
			}
			UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
			_current = this;
		}

		private void Update()
		{
			for (int i = 0; i < updateMethods.Count; i++)
			{
				updateMethods[i]();
			}
		}
	}
}
